package de.dfki.asr.genesis2.sms.oauth;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

/**
 * Servlet implementation class FacebookSubscriber
 */
@WebServlet("/FacebookSubscriber")
public class FacebookSubscriber extends HttpServlet {
	
    protected static final String FACEBOOK_ACCESS_TOKEN_SESSION = "FACEBOOK_ACCESS_TOKEN_SESSION";
    protected static final String redirect_uri = "http://localhost:8080/sms/FacebookOAuthService";
    protected static final String client_id = "400240100000830";
	protected static final String client_secret = "7c46a4fd701e7b0b122e3885c41f8373";
	protected static final String callback_url = "http://localhost:8080/sms/FacebookSubscriptionListener";
	protected static final String callback_encurl = "http%3A%2F%2Flocalhost%3A8080%2Fsms%2FFacebookSubscriptionListener";
	protected static final String accessToken_url = "https://graph.facebook.com/oauth/access_token?";
	protected static final String requestCode_url = "https://www.facebook.com/dialog/oauth/?";
	protected static final String user_scope = "user_about_me,user_activities,user_checkins,user_events,user_hometown,user_likes,user_notes,user_photos,user_status,user_videos,user_work_history,email";
	protected static final String friends_scope = "friends_about_me,friends_activities,friends_checkins,friends_events,friends_hometown,friends_likes,friends_notes,friends_photos,friends_status,friends_videos,friends_work_history";
	protected static final String extended_scope = "read_friendlists,read_mailbox,read_stream";
	protected static final String openGraph_scope = "user_actions.music,user_actions.news,user_actions.video";
	protected static final String app_accessToken = "400240100000830|yCv6s7EI1QPb6sEUJDRvoEos5mg";
	
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FacebookSubscriber() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpClient client = new DefaultHttpClient();
		String url = "https://graph.facebook.com/400240100000830/subscriptions?object=user&fields=name,friends,feed&callback_url=http%3A%2F%2Flocalhost%3A8080%2Fsms%2FFacebookSubscriptionListener&verify_token=123&access_token=400240100000830%7CyCv6s7EI1QPb6sEUJDRvoEos5mg";
		HttpPost post = new HttpPost(url);
		HttpResponse resp = client.execute(post);
		String body = EntityUtils.toString(resp.getEntity());
		System.out.println(body);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
